<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--部门数据-->
      <el-col :span="4" :xs="24">
        <div class="head-container">
          <el-input
            v-model="deptName"
            placeholder="请输入部门名称"
            clearable
            size="small"
            prefix-icon="el-icon-search"
            style="margin-bottom: 20px"
          />
        </div>
        <div class="head-container">
          <el-tree
            :data="deptOptions"
            :props="defaultProps"
            :expand-on-click-node="false"
            :filter-node-method="filterNode"
            ref="tree"
            default-expand-all
            @node-click="handleNodeClick"
          />
        </div>
      </el-col>
      <el-col :span="20" :xs="24">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">

          <el-form-item label="采集时间" prop="passtime">
            <el-input
              v-model="queryParams.passtime"
              placeholder="请输入采集时间"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="姓名" prop="name">
            <el-input
              v-model="queryParams.name"
              placeholder="请输入姓名"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="证件号" prop="idcard">
            <el-input
              v-model="queryParams.idcard"
              placeholder="请输入证件号"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>

          <el-form-item label="设备编号" prop="equipmentid">
            <el-input
              v-model="queryParams.equipmentid"
              placeholder="请输入设备编号"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="设备名称" prop="equipmentname">
            <el-input
              v-model="queryParams.equipmentname"
              placeholder="请输入设备名称"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>

          <el-form-item>
            <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            <el-button
              type="warning"
              icon="el-icon-download"
              size="mini"
              @click="handleExport"
              v-hasPermi="['system:record:export']"
            >导出</el-button>
          </el-form-item>
        </el-form>

<!--        <el-row :gutter="10" class="mb8">-->
<!--          <el-col :span="1.5">-->
<!--            <el-button-->
<!--              type="warning"-->
<!--              icon="el-icon-download"-->
<!--              size="mini"-->
<!--              @click="handleExport"-->
<!--              v-hasPermi="['system:record:export']"-->
<!--            >导出-->
<!--            </el-button>-->
<!--          </el-col>-->
<!--          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
<!--        </el-row>-->

        <el-table v-loading="loading" :data="recordList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center"/>
          <el-table-column align="center" label="证件照">
            <template slot-scope="scope">
              <el-image
                ref="lazyImg"
                lazy
                class="vx-lazyLoad"
                style='height:75px;width:75px;'
                :src="scope.row.idcardimg"
                :fit="fit"
                :preview-src-list="[scope.row.idcardimg]"
              >
                <div slot="placeholder" class="image-slot">
                  <i class="el-icon-loading"/>加载中
                </div>
                <div slot="error" class="image-slot">
                  <i class="el-icon-picture-outline"/>
                </div>
              </el-image>
            </template>
          </el-table-column>
          <el-table-column align="center" label="抓拍照">
            <template slot-scope="scope">
              <el-image
                ref="lazyImg"
                lazy
                class="vx-lazyLoad"
                style='height:75px;width:75px;'
                :src="scope.row.personimg"
                :fit="fit"
                :preview-src-list="[scope.row.personimg]"
              >
                <div slot="placeholder" class="image-slot">
                  <i class="el-icon-loading"/>加载中
                </div>
                <div slot="error" class="image-slot">
                  <i class="el-icon-picture-outline"/>
                </div>
              </el-image>
            </template>
          </el-table-column>
          <el-table-column label="姓名" align="center" prop="name"/>
          <el-table-column label="性别" align="center" prop="gender"/>
          <el-table-column label="人证一致" align="center" prop="isconsist"/>
          <el-table-column label="民族" align="center" prop="nation"/>
          <el-table-column label="出生年月日" align="center" prop="birthday"/>
          <el-table-column label="证件号" align="center" prop="idcard"/>
          <el-table-column label="住址信息" align="center" prop="address"/>
          <el-table-column label="采集时间" align="center" prop="passtime"/>
          <el-table-column label="温度" align="center" prop="temperature"/>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['system:record:edit']"
              >详细
              </el-button>
              <!--              <el-button-->
              <!--                size="mini"-->
              <!--                type="text"-->
              <!--                icon="el-icon-delete"-->
              <!--                @click="handleDelete(scope.row)"-->
              <!--                v-hasPermi="['system:record:remove']"-->
              <!--              >删除-->
              <!--              </el-button>-->
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>

    <!-- 添加或修改采集记录表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">


        <el-row>
          <el-col :span="12">
            <el-form-item label="身份证照片" prop="idcardimg">
              <el-image
                ref="lazyImg"
                lazy
                class="vx-lazyLoad"
                style='height:200px;width:150px;'
                :src="form.idcardimg"
                :preview-src-list="[form.idcardimg]"
              >
                <div slot="placeholder" class="image-slot">
                  <i class="el-icon-loading"/>加载中
                </div>
                <div slot="error" class="image-slot">
                  <i class="el-icon-picture-outline"/>
                </div>
              </el-image>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="采集照片" prop="personimg">
              <el-image
                ref="lazyImg"
                lazy
                class="vx-lazyLoad"
                style='height:200px;width:150px;'
                :src="form.personimg"
                :preview-src-list="[form.personimg]"
              >
                <div slot="placeholder" class="image-slot">
                  <i class="el-icon-loading"/>加载中
                </div>
                <div slot="error" class="image-slot">
                  <i class="el-icon-picture-outline"/>
                </div>
              </el-image>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="采集时间" prop="passtime">
              <el-input v-model="form.passtime" placeholder="请输入采集时间"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="温度" prop="temperature">
              <el-input v-model="form.temperature" placeholder="请输入温度"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="姓名" prop="name">
              <el-input v-model="form.name" placeholder="请输入姓名"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="性别" prop="gender">
              <el-input v-model="form.gender" placeholder="请输入性别"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="人证是否一致" prop="isconsist">
              <el-input v-model="form.isconsist" placeholder="请输入人证是否一致"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="人证相似度" prop="comparescore">
              <el-input v-model="form.comparescore" placeholder="请输入人证相似度"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="民族" prop="nation">
              <el-input v-model="form.nation" placeholder="请输入民族"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="证件号" prop="idcard">
              <el-input v-model="form.idcard" placeholder="请输入证件号"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="出生年月日" prop="birthday">
              <el-input v-model="form.birthday" placeholder="请输入出生年月日"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="住址信息" prop="address">
              <el-input v-model="form.address" placeholder="请输入住址信息"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="有效期开始时间" prop="validitystart">
              <el-input v-model="form.validitystart" placeholder="请输入有效期开始时间"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="有效期结束时间" prop="validityend">
              <el-input v-model="form.validityend" placeholder="请输入有效期结束时间"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="证件类型" prop="cardtype">
              <el-select v-model="form.cardtype" placeholder="请选择证件类型">
                <el-option label="请选择字典生成" value=""/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="地区代码" prop="countryorareacode">
              <el-input v-model="form.countryorareacode" placeholder="请输入国籍或所在地区代码"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="地区名称" prop="countryorareaname">
              <el-input v-model="form.countryorareaname" placeholder="请输入国籍或所在地区名称"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="证件版本号" prop="cardversion">
              <el-input v-model="form.cardversion" placeholder="请输入证件版本号"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="受理机关代码" prop="currentapplyorgcode">
              <el-input v-model="form.currentapplyorgcode" placeholder="请输入当次申请受理机关代码"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="签发次数" prop="signnum">
              <el-input v-model="form.signnum" placeholder="请输入签发次数"/>
            </el-form-item>
          </el-col>
        </el-row>


        <el-row>
          <el-col :span="12">
            <el-form-item label="签发机关" prop="authority">
              <el-input v-model="form.authority" placeholder="请输入签发机关"/>
            </el-form-item>
          </el-col>
        </el-row>


        <el-row>
          <el-col :span="12">
            <el-form-item label="经度" prop="x">
              <el-input v-model="form.x" placeholder="请输入经度"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="纬度" prop="y">
              <el-input v-model="form.y" placeholder="请输入纬度"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="行政区划代码" prop="areacode">
          <el-input v-model="form.areacode" placeholder="请输入行政区划代码"/>
        </el-form-item>

        <el-row>
          <el-col :span="12">
            <el-form-item label="设备编号" prop="equipmentid">
              <el-input v-model="form.equipmentid" placeholder="请输入设备编号"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="设备名称" prop="equipmentname">
              <el-input v-model="form.equipmentname" placeholder="请输入设备名称"/>
            </el-form-item>
          </el-col>
        </el-row>


        <el-form-item label="设备类型" prop="equipmenttype">
          <el-select v-model="form.equipmenttype" placeholder="请选择设备类型">
            <el-option label="请选择字典生成" value=""/>
          </el-select>
        </el-form-item>
        <el-form-item label="设备所在位置名称" prop="location">
          <el-input v-model="form.location" placeholder="请输入设备所在位置名称"/>
        </el-form-item>
        <el-row>
          <el-col :span="12">
            <el-form-item label="警务站编号" prop="stationid">
              <el-input v-model="form.stationid" placeholder="请输入警务站编号"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="警务站名称" prop="stationname">
              <el-input v-model="form.stationname" placeholder="请输入警务站名称"/>
            </el-form-item>
          </el-col>
        </el-row>


        <el-form-item label="回传的接口URL" prop="backurl">
          <el-input v-model="form.backurl" placeholder="请输入回传的接口URL"/>
        </el-form-item>

        <el-form-item label="出入标识">
          <el-radio-group v-model="form.status">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="小区名称" prop="dareaname">
          <el-input v-model="form.dareaname" placeholder="请输入小区名称"/>
        </el-form-item>
        <el-form-item label="小区编号" prop="dareacode">
          <el-input v-model="form.dareacode" placeholder="请输入小区编号"/>
        </el-form-item>
        <el-form-item label="场所类别" prop="placetype">
          <el-select v-model="form.placetype" placeholder="请选择场所类别">
            <el-option label="请选择字典生成" value=""/>
          </el-select>
        </el-form-item>
        <el-form-item label="人员类别" prop="identity">
          <el-input v-model="form.identity" placeholder="请输入人员类别"/>
        </el-form-item>
        <el-form-item label="实际家庭住址" prop="homeplace">
          <el-input v-model="form.homeplace" placeholder="请输入实际家庭住址"/>
        </el-form-item>
        <el-form-item label="联系电话" prop="contact">
          <el-input v-model="form.contact" placeholder="请输入联系电话"/>
        </el-form-item>






        <el-form-item label="开门方式" prop="openmode">
          <el-input v-model="form.openmode" placeholder="请输入开门方式"/>
        </el-form-item>
        <el-form-item label="访问事由" prop="visitreason">
          <el-input v-model="form.visitreason" placeholder="请输入访问事由"/>
        </el-form-item>

        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注"/>
        </el-form-item>
<!--        <el-form-item label="部门id" prop="deptId">-->
<!--          <el-input v-model="form.deptId" placeholder="请输入部门id"/>-->
<!--        </el-form-item>-->
      </el-form>

    </el-dialog>
  </div>
</template>

<script>
import {listRecord, getRecord, delRecord, addRecord, updateRecord, exportRecord} from "@/api/system/record";
import {treeselect} from "@/api/system/dept";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";


export default {
  name: "Record",
  components: {},
  data() {
    return {
      fit: 'contain', // 想要什么属性就在这个位置设置什么属性
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 部门树选项
      deptOptions: undefined,
      // 部门名称
      deptName: undefined,
      // 总条数
      total: 0,
      // 采集记录表表格数据
      recordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        ver: null,
        passtime: null,
        name: null,
        gender: null,
        nation: null,
        idcard: null,
        cardtype: null,
        countryorareacode: null,
        countryorareaname: null,
        cardversion: null,
        currentapplyorgcode: null,
        signnum: null,
        birthday: null,
        address: null,
        authority: null,
        validitystart: null,
        validityend: null,
        idcardimg: null,
        personimg: null,
        areacode: null,
        x: null,
        y: null,
        equipmentid: null,
        equipmentname: null,
        equipmenttype: null,
        stationid: null,
        stationname: null,
        backurl: null,
        location: null,
        status: null,
        dareaname: null,
        dareacode: null,
        placetype: null,
        identity: null,
        homeplace: null,
        contact: null,
        isconsist: null,
        comparescore: null,
        openmode: null,
        visitreason: null,
        visitor: null,
        temperature: null,
        deptId: null
      },
      // 表单参数
      form: {},
      defaultProps: {
        children: "children",
        label: "label"
      },
      // 表单校验
      rules: {}
    };
  },
  watch: {
    // 根据名称筛选部门树
    deptName(val) {
      this.$refs.tree.filter(val);
    }
  },
  created() {
    this.getList();
    this.getTreeselect();
  },
  methods: {
    /** 查询采集记录表列表 */
    getList() {
      this.loading = true;
      listRecord(this.queryParams).then(response => {
        this.recordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        ver: null,
        id: null,
        passtime: null,
        name: null,
        gender: null,
        nation: null,
        idcard: null,
        cardtype: null,
        countryorareacode: null,
        countryorareaname: null,
        cardversion: null,
        currentapplyorgcode: null,
        signnum: null,
        birthday: null,
        address: null,
        authority: null,
        validitystart: null,
        validityend: null,
        idcardimg: null,
        personimg: null,
        areacode: null,
        x: null,
        y: null,
        equipmentid: null,
        equipmentname: null,
        equipmenttype: null,
        stationid: null,
        stationname: null,
        backurl: null,
        location: null,
        status: "0",
        dareaname: null,
        dareacode: null,
        placetype: null,
        identity: null,
        homeplace: null,
        contact: null,
        isconsist: null,
        comparescore: null,
        openmode: null,
        visitreason: null,
        visitor: null,
        temperature: null,
        remark: null,
        deptId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加采集记录表";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getRecord(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "采集记录表";
      });
    },
    /** 查询部门下拉树结构 */
    getTreeselect() {
      treeselect().then(response => {
        this.deptOptions = response.data;
      });
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.queryParams.deptId = data.id;
      this.getList();
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateRecord(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRecord(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除采集记录表编号为"' + ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return delRecord(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有采集记录表数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return exportRecord(queryParams);
      }).then(response => {
        this.download(response.msg);
      })
    }
  }
};
</script>
